package araujoCoronelVillamayor.plantasVsZombies.domain;

import araujoCoronelVillamayor.plantasVsZombies.domain.Planta;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.uqbar.commons.utils.Observable;

@Observable
@SuppressWarnings("all")
public class JardinZen implements Serializable {
  private ArrayList<Planta> _plantas;
  
  public ArrayList<Planta> getPlantas() {
    return this._plantas;
  }
  
  public void setPlantas(final ArrayList<Planta> plantas) {
    this._plantas = plantas;
  }
  
  private static int cantidadMaximaPlantasAcuaticas = 20;
  
  private static int cantidadMaximaPlantasTerrestres = 20;
  
  public JardinZen() {
    ArrayList<Planta> _arrayList = new ArrayList<Planta>();
    this.setPlantas(_arrayList);
  }
  
  public Boolean agregarPlanta(final Planta unaPlanta) {
    Boolean _xifexpression = null;
    Boolean _hayEspacio = this.hayEspacio(unaPlanta);
    if ((_hayEspacio).booleanValue()) {
      ArrayList<Planta> _plantas = this.getPlantas();
      boolean _add = _plantas.add(unaPlanta);
      _xifexpression = Boolean.valueOf(_add);
    } else {
      _xifexpression = null;
    }
    return _xifexpression;
  }
  
  public Boolean hayEspacio(final Planta unaPlanta) {
    Boolean _xifexpression = null;
    boolean _sosPlantaAcuatica = unaPlanta.sosPlantaAcuatica();
    if (_sosPlantaAcuatica) {
      int _cantidadPlantasAcuaticas = this.cantidadPlantasAcuaticas();
      return (_cantidadPlantasAcuaticas < JardinZen.cantidadMaximaPlantasAcuaticas);
    } else {
      Boolean _xifexpression_1 = null;
      boolean _sosPlantaTerrestre = unaPlanta.sosPlantaTerrestre();
      if (_sosPlantaTerrestre) {
        int _cantidadPlantasTerrestres = this.cantidadPlantasTerrestres();
        return (_cantidadPlantasTerrestres < JardinZen.cantidadMaximaPlantasTerrestres);
      }
      _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
  }
  
  public Iterable<Planta> damePlantasAcuaticas() {
    Iterable<Planta> _xifexpression = null;
    ArrayList<Planta> _plantas = this.getPlantas();
    boolean _isEmpty = _plantas.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      ArrayList<Planta> _plantas_1 = this.getPlantas();
      final Function1<Planta,Boolean> _function = new Function1<Planta,Boolean>() {
        public Boolean apply(final Planta planta) {
          boolean _sosPlantaAcuatica = planta.sosPlantaAcuatica();
          return Boolean.valueOf(_sosPlantaAcuatica);
        }
      };
      Iterable<Planta> _filter = IterableExtensions.<Planta>filter(_plantas_1, _function);
      _xifexpression = _filter;
    }
    return _xifexpression;
  }
  
  public Iterable<Planta> damePlantasTerrestres() {
    Iterable<Planta> _xifexpression = null;
    ArrayList<Planta> _plantas = this.getPlantas();
    boolean _isEmpty = _plantas.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      ArrayList<Planta> _plantas_1 = this.getPlantas();
      final Function1<Planta,Boolean> _function = new Function1<Planta,Boolean>() {
        public Boolean apply(final Planta planta) {
          boolean _sosPlantaTerrestre = planta.sosPlantaTerrestre();
          return Boolean.valueOf(_sosPlantaTerrestre);
        }
      };
      Iterable<Planta> _filter = IterableExtensions.<Planta>filter(_plantas_1, _function);
      _xifexpression = _filter;
    }
    return _xifexpression;
  }
  
  public int cantidadPlantasAcuaticas() {
    ArrayList<Planta> _plantas = this.getPlantas();
    boolean _isEmpty = _plantas.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      Iterable<Planta> _damePlantasAcuaticas = this.damePlantasAcuaticas();
      return IterableExtensions.size(_damePlantasAcuaticas);
    } else {
      return 0;
    }
  }
  
  public int cantidadPlantasTerrestres() {
    ArrayList<Planta> _plantas = this.getPlantas();
    boolean _isEmpty = _plantas.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      Iterable<Planta> _damePlantasTerrestres = this.damePlantasTerrestres();
      return IterableExtensions.size(_damePlantasTerrestres);
    } else {
      return 0;
    }
  }
  
  public boolean quitarPlanta(final Planta unaPlanta) {
    ArrayList<Planta> _plantas = this.getPlantas();
    boolean _remove = _plantas.remove(unaPlanta);
    return _remove;
  }
  
  public List<Planta> search(final String tipo) {
    ArrayList<Planta> _plantas = this.getPlantas();
    final Function1<Planta,Boolean> _function = new Function1<Planta,Boolean>() {
      public Boolean apply(final Planta planta) {
        String _tipo = planta.getTipo();
        boolean _equals = _tipo.equals(tipo);
        return Boolean.valueOf(_equals);
      }
    };
    Iterable<Planta> _filter = IterableExtensions.<Planta>filter(_plantas, _function);
    List<Planta> _list = IterableExtensions.<Planta>toList(_filter);
    return _list;
  }
}
